﻿using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.ActiveDirectory.Model
{
    public class Connection
    {
        private string _ldapPath = "LDAP://vail.rubios.com/";
        private string _username = "Domain1\\t-acabreros"; // replace with your username here
        private string _password = "Nu091097092"; // replace with your password here

        public DirectorySearcher Searcher { get; set; }
        public DirectoryEntry Entry { get; set; }

        public Connection()
        {
            Console.WriteLine("> Working over the VPN...");
            DirectoryEntry RootDSE = new DirectoryEntry(_ldapPath + "RootDSE", _username, _password);
            String DomainDN = RootDSE.Properties["DefaultNamingContext"].Value.ToString();
            Entry = new DirectoryEntry(_ldapPath + DomainDN, _username, _password);

            if (Searcher == null)
            {
                Searcher = new DirectorySearcher(Entry);
                Searcher.SearchScope = SearchScope.Subtree;
            }
        }
    }
}
